package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseSaleAttr;
import com.atguigu.gmall.product.model.SpuInfo;
import com.atguigu.gmall.product.service.SpuManageService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author terminal
 * @since 2023-06-08 14:01
 */
@RestController
@RequestMapping("/admin/product")
public class SpuManageController {
    @Resource
    private SpuManageService spuManageService;

    /**
     * 商品spu分页
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/{page}/{size}")
    public Result getSpuByPage(@PathVariable("page") Long page,
                               @PathVariable("size") Long size,
                               @RequestParam("category3Id") Long category3Id ){
        Page<SpuInfo> spuInfoPage = new Page<>(page, size);
        spuInfoPage = spuManageService.getSpuByPage(spuInfoPage,category3Id);
        return Result.ok(spuInfoPage);
    }

    /**
     * 获取销售属性数据
     * @return
     */
    @GetMapping("/baseSaleAttrList")
    public Result getBaseSaleAttrList(){
        List<BaseSaleAttr> list = spuManageService.getBaseSaleAttrList();
        return Result.ok(list);
    }

    /**
     * 保存spu
     * @param spuInfo
     * @return
     */
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        spuManageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }
}
